
<form role="form" class="epii" method="post" data-form="1" action="{url card recharge }">

    <div class="form-group">
        <label><span style="color: red">*</span>卡分类：</label>
        <select class="selectpicker" name="" id="card_cate_id" >
            {:options,$cardCate,$info.card_cate_id}
        </select>
    </div>
    <div class="form-group">
        <label><span style="color: red">*</span>当前金额：</label>
        <input type="number" class="form-control" name=""  value="{? $info.money}"
               placeholder="请输入充值金额" readonly>
    </div>
    <div class="form-group">
        <label><span style="color: red">*</span>充值金额：</label>
        <input type="number" class="form-control" name="r[recharge_money]"  value=""
               placeholder="请输入充值金额" id="recharge">
    </div>
    <div class="form-group">
        <label>赠送金额：</label>
        <input type="number" class="form-control" name="r[gift_money]"  value=""
               placeholder="赠送金额" id="gift_money">
    </div>
    <input type="hidden" name="id" value="{$id?0}">
    <div class="form-footer">
        <button type="submit" class="btn btn-primary">提交</button>
    </div>
</form>
<script src="{$laydate}/laydate.js"></script>
<script type="text/javascript">

    window.onEpiiInit(function() {

        $('#gift_money').focus(function () {
            giftMoney()
            // layer.close(loading)
        });
        $('#recharge').change(function () {
            giftMoney()
            // layer.close(loading)
        });
    });
    function giftMoney(){
        let recharge_money=$('#recharge').val();
        let card_cate_id=$('#card_cate_id').val();
        if (recharge_money.length==0){
            layer.msg('请填写充值金额');
            return;
        }
        if(card_cate_id==''){
            layer.msg('请先选择卡分类');
            return;
        }
        var loading=layer.load(1);
        $.ajax({
            url: '?app=card@getGiftMoney&recharge_money='+recharge_money+'&card_cate_id='+card_cate_id,
            type: 'get',
            dataType:'json',
            success: function(res) {
                if(res.code==1){
                    $('#gift_money').val(res.data.gift_money);
                }
                layer.close(loading)
            }
        });
    }

</script>
